//获取用户粉丝关注列表：/get-follow-fans-like
import http from 'k6/http';
import { check } from 'k6';
import { URL } from './config.js';

// 1. 压测场景：10 个虚拟用户，持续 30 秒
export const options = {
  vus: 10,
  duration: '30s',
};

// 2. 常量
//const BASE = 'https://dev.xiaobeiyangji.com/yangji-api';
const BASE = `${URL}/yangji-api`;

export default function () {
  // 登录 → 拿 accessToken: https://dev.xiaobeiyangji.com/api/login/phone
  const loginRes = http.post(`${BASE}/api/login/phone`,JSON.stringify({
      phone: '15298055260',
      code: '666666',
      clientType: 'PHONE'
    }),
    { headers: { 'Content-Type': 'application/json' } }
  );
  //  https://api.xiaobeiyangji.com/api/get-follow-fans-like
  const payload=JSON.stringify(
{"type":"fans","unionId":"o896o5_scUqyJKkRTR1z9Wbm4V98","page":2,"pageSize":10,"version":"3.4.0.X"}
  );

  // 简单断言
  check(loginRes, { 'login 200': r => r.status === 200 });

  // 提取 token（返回体在 data.accessToken）
  const token = loginRes.json('data.accessToken');

  // ② 用 token 调 /api/get-follow-fans-like
  const verRes = http.post(`${BASE}/api/get-follow-fans-like`,payload,{ headers: {'Content-Type': 'application/json', Authorization: `Bearer ${token}` } }
  );
  console.log('状态码',verRes.status);
  console.log('返回值',verRes.body);
}